<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue中多个元素或组件的过度</title>
    <style>
        .v-enter, v-leave-to {
            opacity: 0;
        }

        .v-enter-active,.v-leave-active {
            transition: opacity 1s;
        }
    </style>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- mode指定效果  这里先隐藏再显示 transition上没有name属性，则类class前缀已v-开头，否则以name名开头 -->
        <transition mode="out-in">
            <!-- 加上key之后就不会有dom复用  动画效果就出来了 -->
            <!--<div v-if="show" key="hello">Hello World</div>-->
            <!--<div v-else key="bye">Bye World</div>-->
            <component :is="type"></component>
        </transition>

        <button @click="handleClick">toggle</button>
    </div>
    <script>
        Vue.component("child-one", {
            template : "<div>child-one</div>"
        })

        Vue.component("child-two", {
            template : "<div>child-two</div>"
        })

        new Vue({
            el : "#app",
            data : {
                // show : true
                type : "child-one"
            },
            methods : {
                handleClick : function () {
                    // this.show = !this.show ;
                    this.type = this.type === "child-one" ? "child-two" : "child-one"
                }
            }
        })
    </script>
</body>
</html>